package cn.sdormitory.controller.exam;

import cn.sdormitory.common.api.CommonPage;
import cn.sdormitory.common.api.CommonResult;
import cn.sdormitory.exam.service.ExamInfoService;
import cn.sdormitory.exam.vo.ExamConfigVo;
import cn.sdormitory.exam.vo.ExamInfoVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Api(tags = "exam => 考试管理")
@RequestMapping("/exam/info")
public class ExamInfoController {
	
	@Resource
	private ExamInfoService examInfoService;
	
	@ApiOperation("分页查询列表")
	@PostMapping("/pageList")
//    @PreAuthorize("@ss.hasPermi('exam:info:list')")
	public CommonResult<CommonPage<ExamInfoVO>> findExamInfoPageList(@RequestBody ExamInfoVO examInfoVO) {
		IPage<ExamInfoVO> pageList = examInfoService.findExamInfoPageList(examInfoVO);
		return CommonResult.success(CommonPage.restPage(pageList));
	}
	
	@ApiOperation("新增or修改考试信息")
	@PostMapping("/edit")
//    @PreAuthorize("@ss.hasPermi('exam:info:edit')")
	public CommonResult<CommonPage<ExamInfoVO>> addOrUpdateExamInfo(@RequestBody ExamInfoVO examInfoVO) {
		int num = examInfoService.addOrUpdateExamInfo(examInfoVO);
		if (num > 0) return CommonResult.success();
		return CommonResult.failed();
	}
	
	@ApiOperation("根据ID删除考试信息")
	@PostMapping("/delete")
//    @PreAuthorize("@ss.hasPermi('exam:info:delete')")
	public CommonResult<CommonPage<ExamInfoVO>> deleteExamInfoById(@RequestBody ExamInfoVO examInfoVO) {
		int num = examInfoService.deleteExamInfoById(examInfoVO);
		if (num > 0) return CommonResult.success();
		return CommonResult.failed();
	}
	
	@ApiOperation("批量删除考试信息")
	@PostMapping("/deleteBatch")
//    @PreAuthorize("@ss.hasPermi('exam:info:deleteBatch')")
	public CommonResult<Integer> deleteBatchExamInfo(@RequestBody List<ExamInfoVO> list) {
		int num = examInfoService.deleteBatchExamInfo(list);
		if (num > 0) return CommonResult.success();
		return CommonResult.failed();
	}
	
	@ApiOperation("批量修改考试信息状态")
	@PostMapping("/updateBatch")
//    @PreAuthorize("@ss.hasPermi('exam:info:deleteBatch')")
	public CommonResult<Integer> updateBatchExamInfo(@RequestBody List<ExamInfoVO> list) {
		int num = examInfoService.updateBatchExamInfo(list);
		if (num > 0) return CommonResult.success();
		return CommonResult.failed();
	}
}
